package kotlinlearn

import java.lang.StringBuilder
import kotlin.math.max

fun main() {
//    var a: Int = 10
//    a *= 10
//    println("a = $a")
//    val a = 37
//    val b = 40
//    val value = largerNumber(a, b)
//    println("larger number is $value")

//    checkNumber(a)

//    for (i in 0 until 10) {
//        println(i)
//    }
//    val person = Person()
//    person.name = "Jack"
//    person.age = 18
//    person.eat()

//    val student = Student("a123", 5, "Jack", 19)
//    val cellphone1 = Cellphone("samsung", 2399.9)
//    val cellphone2 = Cellphone("samsung", 2399.9)
//    println(cellphone1)
//    println("cellphone1 equals cellphone2 " + (cellphone1 == cellphone2))

//    val list = listOf<String>("apple", "banana")
//    for (fruit in list) {
//        println(fruit)
//    }

//    Thread {
//        println("Thread is running")
//    }.start()

//    useWith()

//    Util.doAction2()

    doSomething()
}

fun useWith() {
    val list = listOf("apple", "orig", "banana", "pear")
    val result = with(StringBuilder()) {
        append("start eating fruits.\n")
        for (s in list) {
            append(s).append("\n")
        }
        append("Ate all fruits.")
        toString()
    }
    println(result)
}

fun doStudy(study: Study?) {
    study?.let {
        it.doSomething()
        it.doHomeWork()
    }
}

fun largerNumber(num1: Int, num2: Int): Int = max(num1, num2)

fun largerNumber2(num1: Int, num2: Int): Int {
    return if (num1 > num2) {
        num1
    } else {
        num2
    }
}

fun checkNumber(num: Number) {
    when (num) {
        is Int -> println("num is int")
        is Double -> println("num is double")
        else -> println("num is not support")
    }
}